home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / text / hyper / gmake.lha / gmake / c_source / type.c < prev   
C/C++ Source or Header  |  1995-08-22  |  3KB  |  170 lines

  1. // These are the commands for effecting the types list.
  2.  
  3. #include "standard.h"
  4.  
  5. struct node
  6.         {
  7.          FileType type;
  8.          MTEXT file;
  9.      MTEXT arg;
  10.         };
  11.  
  12. struct link
  13.         {
  14.          struct node * thisnode;
  15.          struct link * rest;
  16.         };
  17.  
  18. typedef struct node  *Citem;
  19. typedef struct link *Clist;
  20. static Clist nodelist=NULL;
  21. static Clist pagelist;
  22. #define NUMTYPE 50
  23.  
  24. static BOOL typeX[NUMTYPE];
  25. static MTEXT current_arg;
  26. static int pagenum = 0;
  27.  
  28. set_pagelist()
  29.  {
  30.   pagelist = nodelist;
  31.  }
  32.  
  33. int page_num()
  34.  {
  35.   return pagenum;
  36.  }
  37.  
  38. init_typearray()
  39.  {
  40.   int i;
  41.   for(i=0;i<NUMTYPE;i++)
  42.     {
  43.     typeX[i] = FALSE;
  44.     }
  45.   strcpy(current_arg,"");
  46.  }
  47.  
  48. Clist cons( Citem x, Clist xl)
  49.         {
  50.         Clist cnew;
  51.         cnew=malloc(sizeof(struct link));
  52.         cnew->thisnode = x;
  53.         cnew->rest = xl;
  54.         return(cnew);
  55.         }
  56.  
  57.  
  58. add_type(FileType type, char * file, char * arg)
  59.  {
  60.   Clist currentlist;
  61.   currentlist = nodelist;
  62.   Citem cn;
  63.  
  64.   NOTE("Adding file: ",file);
  65.   space_control(arg); // This will enable the contents to look neater.
  66.  
  67.   if((typeX[type]) && (type !=PAGE))
  68.     { REM ("Duplicate type"); return;}
  69.   else
  70.     {typeX[type]=TRUE;} 
  71.         
  72.   if(type ==PAGE)
  73.     pagenum++;
  74.  
  75.    cn = malloc(sizeof(struct node));
  76.    /* Copy data into command structure */
  77.    strcpy(cn->file,file);
  78.    strcpy(cn->arg,arg);
  79.    cn->type=type;
  80.  
  81.  nodelist=cons(cn,currentlist);
  82.  }
  83.  
  84. BOOL exist_type(FileType type)
  85.  {
  86.   // For the purposes of wheth
  87.   return typeX[type];
  88.  }
  89.  
  90. check_guidefile()
  91.  {
  92.   if(typeX[GUIDE])
  93.     {
  94.      REM ("Guidefile exists");
  95.     }
  96.   else
  97.     {
  98.      REM ("Guidefile NOT exists: using default file");
  99.      add_type(GUIDE,"output.guide","");
  100.     }
  101.  }
  102.  
  103. char * get_nodedesc()
  104.  {
  105.     NOTE ("Current node description: ",current_arg);
  106.     return current_arg;
  107.  }
  108.  
  109. char * getfilename(FileType type)
  110.  {
  111.    NOTE ("NameRequest: ",txt_type(type));
  112.    if(type != PAGE)
  113.      {
  114.      Clist temp;
  115.      temp = nodelist;
  116.  
  117.      while(temp != NULL)
  118.      {    
  119.          if(type == temp->thisnode->type)
  120.             {
  121.             strcpy(current_arg,temp->thisnode->arg);
  122.             return temp->thisnode->file;
  123.             }
  124.         else
  125.             temp = temp->rest;
  126.      }
  127.      return ""; // Failed    
  128.     
  129.     }
  130.    else
  131.     {
  132.      return "";  // Fail
  133.     }
  134.  }
  135.  
  136. char * page_file(int number)
  137.  {
  138.   Clist temp;
  139.   temp = nodelist;
  140.   FileType type = PAGE;
  141.   int i = 1;
  142.  
  143.   REM("Page file request");
  144.  
  145.   while(temp != NULL)
  146.          {
  147.                 if(type == temp->thisnode->type)
  148.                         {
  149.              if(i==number)
  150.               {
  151.                            MTEXT current_file;
  152.                            strcpy(current_arg,temp->thisnode->arg);
  153.                            strcpy(current_file,temp->thisnode->file);
  154.                            return current_file;
  155.               }
  156.              else
  157.               {
  158.                i++;
  159.                temp = temp->rest;
  160.               }
  161.                         }
  162.                 else
  163.             {
  164.                            temp = temp->rest;
  165.             }
  166.          }
  167.          strcpy(current_arg,"");
  168.          return "";  // Fail
  169.  }
  170.